const app = getApp()
var xrRequest = require('../../../vendor/hope-sdk/core/request.js');
var config = require('../../../config.js');
var xrSdk = require('../../../vendor/hope-sdk/index.js');
const util = require('../../../utils/util.js');
Page({
  /**
   * 页面的初始数据
   */
  data: {
    modal8: false,
    carList: [],
    car_id: 0,
    car:[]
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },
  initCar: function () {
    var that = this;
    var car_id = that.data.car_id;
    xrRequest.request(app,{
      url: config.service.get_car_list_for_apply,
      login: true,
      data: {
        car_id: car_id,
      },
      success: function (res) {
        if (res.data.code == 1) {
          var id = res.data.data.car ? res.data.data.car.id : 0;
          that.setData({
            carList: res.data.data.list,
            car: res.data.data.car,
            car_id: id
          });
          xrSdk.cookie.set('car_id', id);
        } else {
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
          })
        }
      },
      fail: function (res) { 
        wx.showToast({
          title: res,
          icon: 'none',
        })
      },
      authfail: function (e) {
        wx.navigateTo({
          url: "../../auth/auth"
        })
      }
    })
  },
  show8() {
    this.setData({
      modal8: true
    })
  },
  hide8() {
    this.setData({
      modal8: false
    })
  },
  handleClick() {
    var that = this;
    if (that.data.car_id == 0 || that.data.car_id < 1) {
      util.toast('请选择车辆');
      return;
    }
    that.initCar();
    this.hide8()
  },
  selectRadio: function (e) {
    console.log(e);
    this.setData({
      car_id: e.detail.value
    });
  },
  /**
   * 更换申请
   */
  applyClick:function(e){
    var that = this;
    var tyre = e.currentTarget.dataset.tyre;
    app.WxService.navigateTo("../edit/edit", {
      tyre_id: tyre,
      order_id:0
    });
  },
  /**
   *修改鼓包申请 
   */
  editClick:function(e){
    var that = this;
    var tyre  = e.currentTarget.dataset.tyre;
    var order = e.currentTarget.dataset.order;
    app.WxService.navigateTo("../edit/edit", {
      tyre_id: tyre,
      order_id: order
    });
  },
  /**
   *查看鼓包申请 
   */
  viewClick: function (e) {
    var that = this;
    var order = e.currentTarget.dataset.order;
    app.WxService.navigateTo("../view/view", {
      id: order
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    that.setData({
      car_id: xrSdk.cookie.get('car_id') || 0
    }, () => {
      that.initCar();
    });
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {}
})